<%--
  Created by IntelliJ IDEA.
  User: haodong
  Date: 2022/3/14
  Time: 1:21
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <%--http://localhost:8080/atcrowdfunding/test/ssm.html--%>
    <base href="http://${pageContext.request.serverName}:${pageContext.request.serverPort}${pageContext.request.contextPath}/">
    <script type="text/javascript" src="jquery/jquery-2.1.1.min.js"></script>
    <script type="text/javascript" src="layer/layer.js"></script>
    <script type="text/javascript">

        $(function () {

            $("#btn5").click(function () {

                layer.msg('test layer');

            })

            $("#btn4").click(function () {

                var student = {
                    "stuId":"01",
                    "stuName":"jack",
                    "address":{
                        "province":"广东省",
                        "city":"广州市",
                        "street":"后端"
                    },
                    "subjectList":[
                        {
                        "subjectName":"javaSE",
                        "subjectScore":100
                        },
                        {
                        "subjectName":"SSM",
                        "subjectScore":98
                        }
                    ],
                    "map":{
                        "k1":"v1",
                        "k2":"v2"
                    }
                };

                //将JSON对象转化为JSON字符串
                var studentStr = JSON.stringify(student);

                $.ajax({
                    "url":"test/compose/object.json",
                    "type":"post",
                    "data":studentStr,
                    "dataType":"json",
                    "contentType":"application/json;charset=UTF-8",
                    "success": function (response) {
                          console.log(response)       //服务端成功处理请求后调用的回调函数,response是响应体
                    },
                    "error": function (response) {
                        console.log(response)         //服务端处理请求失败后调用的回调函数
                    }

                });


            });
        })

        $(function () {
            $("#btn1").click(function () {

                $.ajax({
                    "url": "send/array/one.html",    //请求目标资源地址
                    "type": "post",              //请求方式
                    "data": {
                        "array": [5, 8, 12]
                    },                          //发送的请求参数
                    "dataType": "text",           //表示如何对待服务器返回的数据
                    "success": function (response) {
                        alert(response)         //服务端成功处理请求后调用的回调函数,response是响应体
                    },
                    "error": function (response) {
                        alert(response)         //服务端处理请求失败后调用的回调函数
                    }

                });
            });
        })


        $(function () {
            $("#btn2").click(function () {

                $.ajax({
                    "url": "send/array/two.html",    //请求目标资源地址
                    "type": "post",              //请求方式
                    "data": {
                        "array[0]": 5,
                        "array[1]": 8,
                        "array[2]": 12
                    },                          //发送的请求参数
                    "dataType": "text",           //表示如何对待服务器返回的数据
                    "success": function (response) {
                        alert(response)         //服务端成功处理请求后调用的回调函数,response是响应体
                    },
                    "error": function (response) {
                        alert(response)         //服务端处理请求失败后调用的回调函数
                    }

                });
            });


        })
        $(function () {
            $("#btn3").click(function () {

                //准备好要发送到服务器端的数组
                var array =[5,8,12];

                //将JSON数组转化为JSON字符串
                var arrayStr = JSON.stringify(array);

                $.ajax({
                    "url": "send/array/three.html",    //请求目标资源地址
                    "type": "post",              //请求方式
                    "data": arrayStr,                          //请求体
                    "dataType": "text", //表示如何对待服务器返回的数据
                    "contentType":"application/json;charset=UTF-8", //设置请求体的内容类型，告诉服务器本次请求的请求参数为JSON数据
                    "success": function (response) {
                        alert(response)         //服务端成功处理请求后调用的回调函数,response是响应体
                    },
                    "error": function (response) {
                        alert(response)         //服务端处理请求失败后调用的回调函数
                    }

                });
            });


        })


    </script>
</head>
<body>
<%--不使用base标签--%>
<%--    <a href="${pageContext.request.contextPath}/test/ssm.html">测试ssm整合</a>--%>
<%--使用base标签--%>
<a href="test/ssm.html">测试ssm整合</a>

<br/>
<br/>

<button id="btn1">Send [5,8,12] One</button>

<br/>
<br/>

<button id="btn2">Send [5,8,12] Two</button>

<br/>
<br/>

<button id="btn3">Send [5,8,12] Three</button>

<br/>
<br/>

<button id="btn4">Send Compose Object</button>
<br/>
<br/>

<button id="btn5">Test Layer</button>

</body>
</html>
